package com.example.dubbo.consumer.controller;

import com.example.dubbo.api.DemoService;
import com.example.dubbo.api.ReturnObjService;
import com.example.dubbo.dto.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Base64;

@RestController
public class DubboDemoController {

    @Resource
    private DemoService demoService;
    @Resource
    private ReturnObjService returnByteService;
    @Resource
    private ReturnObjService returnListService;
    @Resource
    private ReturnObjService returnMapService;
    @Resource
    private ReturnObjService returnStringService;

    @RequestMapping("/sayHello")
    public String sayHello(String name) {
        return demoService.sayHello(name);
    }

    @RequestMapping("/rtByte")
    public String rtByte(String name) throws IOException {
        Result<byte[]> result = returnByteService.sendMessage(name);

        return new String(Base64.getDecoder().decode(result.getContent()));
    }

    @RequestMapping("/rtStr")
    public Result rtStr(String name) {
        return returnStringService.sendMessage(name);
    }

    @RequestMapping("/rtMap")
    public Result rtMap(String name) {
        return returnMapService.sendMessage(name);
    }

    @RequestMapping("/rtList")
    public Result rtList(String name) {
        return returnListService.sendMessage(name);
    }


}
